package o;

import android.content.Context;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.WindowManager;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Deprecated
public abstract class aab<T extends View, Z> extends zo<Z> {
    private static boolean ˎ;
    private static int ॱ = o.rk.e.ˏ;
    private boolean ʽ;
    protected final T ˊ;
    @Nullable
    private OnAttachStateChangeListener ˋ;
    private final e ˏ;
    private boolean ॱॱ;

    @VisibleForTesting
    static final class e {
        @VisibleForTesting
        @Nullable
        static Integer ˏ;
        boolean ˊ;
        private final List<aaa> ˋ = new ArrayList();
        private final View ˎ;
        @Nullable
        private c ॱ;

        static final class c implements OnPreDrawListener {
            private final WeakReference<e> ˊ;

            c(@NonNull e eVar) {
                this.ˊ = new WeakReference(eVar);
            }

            public boolean onPreDraw() {
                if (Log.isLoggable("ViewTarget", 2)) {
                    Log.v("ViewTarget", "OnGlobalLayoutListener called attachStateListener=" + this);
                }
                e eVar = (e) this.ˊ.get();
                if (eVar != null) {
                    eVar.ˏ();
                }
                return true;
            }
        }

        e(@NonNull View view) {
            this.ˎ = view;
        }

        private static int ˋ(@NonNull Context context) {
            if (ˏ == null) {
                Display defaultDisplay = ((WindowManager) aas.ˎ((WindowManager) context.getSystemService("window"))).getDefaultDisplay();
                Point point = new Point();
                defaultDisplay.getSize(point);
                ˏ = Integer.valueOf(Math.max(point.x, point.y));
            }
            return ˏ.intValue();
        }

        private void ॱ(int i, int i2) {
            Iterator it = new ArrayList(this.ˋ).iterator();
            while (it.hasNext()) {
                ((aaa) it.next()).ˊ(i, i2);
            }
        }

        void ˏ() {
            if (!this.ˋ.isEmpty()) {
                int ˎ = ˎ();
                int ॱ = ॱ();
                if (ˋ(ˎ, ॱ)) {
                    ॱ(ˎ, ॱ);
                    ˋ();
                }
            }
        }

        void ˏ(@NonNull aaa o_aaa) {
            int ˎ = ˎ();
            int ॱ = ॱ();
            if (ˋ(ˎ, ॱ)) {
                o_aaa.ˊ(ˎ, ॱ);
                return;
            }
            if (!this.ˋ.contains(o_aaa)) {
                this.ˋ.add(o_aaa);
            }
            if (this.ॱ == null) {
                ViewTreeObserver viewTreeObserver = this.ˎ.getViewTreeObserver();
                this.ॱ = new c(this);
                viewTreeObserver.addOnPreDrawListener(this.ॱ);
            }
        }

        void ˋ(@NonNull aaa o_aaa) {
            this.ˋ.remove(o_aaa);
        }

        void ˋ() {
            ViewTreeObserver viewTreeObserver = this.ˎ.getViewTreeObserver();
            if (viewTreeObserver.isAlive()) {
                viewTreeObserver.removeOnPreDrawListener(this.ॱ);
            }
            this.ॱ = null;
            this.ˋ.clear();
        }

        private boolean ˋ(int i, int i2) {
            return ˋ(i) && ˋ(i2);
        }

        private int ॱ() {
            int paddingBottom = this.ˎ.getPaddingBottom() + this.ˎ.getPaddingTop();
            LayoutParams layoutParams = this.ˎ.getLayoutParams();
            return ˏ(this.ˎ.getHeight(), layoutParams != null ? layoutParams.height : 0, paddingBottom);
        }

        private int ˎ() {
            int paddingRight = this.ˎ.getPaddingRight() + this.ˎ.getPaddingLeft();
            LayoutParams layoutParams = this.ˎ.getLayoutParams();
            return ˏ(this.ˎ.getWidth(), layoutParams != null ? layoutParams.width : 0, paddingRight);
        }

        private int ˏ(int i, int i2, int i3) {
            int i4 = i2 - i3;
            if (i4 > 0) {
                return i4;
            }
            if (this.ˊ && this.ˎ.isLayoutRequested()) {
                return 0;
            }
            i4 = i - i3;
            if (i4 > 0) {
                return i4;
            }
            if (this.ˎ.isLayoutRequested() || i2 != -2) {
                return 0;
            }
            if (Log.isLoggable("ViewTarget", 4)) {
                Log.i("ViewTarget", "Glide treats LayoutParams.WRAP_CONTENT as a request for an image the size of this device's screen dimensions. If you want to load the original image and are ok with the corresponding memory cost and OOMs (depending on the input size), use override(Target.SIZE_ORIGINAL). Otherwise, use LayoutParams.MATCH_PARENT, set layout_width and layout_height to fixed dimension, or use .override() with fixed dimensions.");
            }
            return ˋ(this.ˎ.getContext());
        }

        private boolean ˋ(int i) {
            return i > 0 || i == Integer.MIN_VALUE;
        }
    }

    public aab(@NonNull T t) {
        this.ˊ = (View) aas.ˎ(t);
        this.ˏ = new e(t);
    }

    @CallSuper
    public void onLoadStarted(@Nullable Drawable drawable) {
        super.onLoadStarted(drawable);
        ˏ();
    }

    private void ˏ() {
        if (this.ˋ != null && !this.ʽ) {
            this.ˊ.addOnAttachStateChangeListener(this.ˋ);
            this.ʽ = true;
        }
    }

    private void ˋ() {
        if (this.ˋ != null && this.ʽ) {
            this.ˊ.removeOnAttachStateChangeListener(this.ˋ);
            this.ʽ = false;
        }
    }

    @CallSuper
    public void getSize(@NonNull aaa o_aaa) {
        this.ˏ.ˏ(o_aaa);
    }

    @CallSuper
    public void removeCallback(@NonNull aaa o_aaa) {
        this.ˏ.ˋ(o_aaa);
    }

    @CallSuper
    public void onLoadCleared(@Nullable Drawable drawable) {
        super.onLoadCleared(drawable);
        this.ˏ.ˋ();
        if (!this.ॱॱ) {
            ˋ();
        }
    }

    public void setRequest(@Nullable zm zmVar) {
        ˋ(zmVar);
    }

    @Nullable
    public zm getRequest() {
        Object ˊ = ˊ();
        if (ˊ == null) {
            return null;
        }
        if (ˊ instanceof zm) {
            return (zm) ˊ;
        }
        throw new IllegalArgumentException("You must not call setTag() on a view Glide is targeting");
    }

    public String toString() {
        return "Target for: " + this.ˊ;
    }

    private void ˋ(@Nullable Object obj) {
        ˎ = true;
        this.ˊ.setTag(ॱ, obj);
    }

    @Nullable
    private Object ˊ() {
        return this.ˊ.getTag(ॱ);
    }

    @Deprecated
    public static void ˊ(int i) {
        if (ˎ) {
            throw new IllegalArgumentException("You cannot set the tag id more than once or change the tag id after the first request has been made");
        }
        ॱ = i;
    }
}
